package com.chaos.system.controller;

import cn.hutool.core.util.ObjectUtil;
import com.chaos.system.api.data.TTenantData;
import com.chaos.system.service.TTenantService;
import com.chaos.framework.model.dto.ID;
import com.chaos.framework.model.dto.page.PageList;
import com.chaos.framework.model.dto.page.PageQueryDto;
import com.chaos.framework.model.dto.result.data.BooleanResult;
import com.chaos.framework.model.dto.result.data.DataResult;
import com.chaos.framework.model.dto.result.list.ListResult;
import com.chaos.framework.model.dto.result.page.PageResult;
import com.chaos.framework.starter.base.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Jacky.Cui
 * @since 2024-12-02
 */
@Slf4j
@RestController
@Api(tags = "租户：B 端用户")
@RequestMapping("/tTenant")
public class TTenantController extends BaseController<TTenantData> {
    @Resource
    private TTenantService tTenantService;

    @PostMapping("/one.admin")
    @ApiOperation(value = "租户：B 端用户详情", httpMethod = "POST")
    public DataResult<TTenantData> one(@RequestBody ID data) {
        return dataResult(tTenantService.selectByID(data));
    }

    @PostMapping("/list.admin")
    @ApiOperation(value = "租户：B 端用户列表", httpMethod = "POST")
    public ListResult<TTenantData> list(@RequestBody TTenantData data) {
        return listResult(tTenantService.selectByData(data));
    }

    @PostMapping("/page.admin")
    @ApiOperation(value = "租户：B 端用户分页", httpMethod = "POST")
    public PageResult<TTenantData> page(@RequestBody PageQueryDto<TTenantData> data) {
        PageList<TTenantData> page = tTenantService.selectByPage(data);
        return pageResult(page);
    }

    @PostMapping("/add.admin")
    @ApiOperation(value = "新增租户：B 端用户", httpMethod = "POST")
    public DataResult<ID> add(@RequestBody TTenantData data) {
        return dataResult(tTenantService.insertModel(data));
    }

    @PostMapping("/update.admin")
    @ApiOperation(value = "编辑租户：B 端用户", httpMethod = "POST")
    public BooleanResult update(@RequestBody TTenantData data) {
        return booleanResult(tTenantService.updateModelByID(data));
    }

    @PostMapping("/delete.admin")
    @ApiOperation(value = "删除租户：B 端用户", httpMethod = "POST")
    public BooleanResult delete(@RequestBody ID data) {
        return booleanResult(tTenantService.deleteModel(data));
    }


}
